package com.fms.gui.emailer.components;

import java.util.ArrayList;
import java.util.List;

import com.fms.model.domain.FlowSheet;
import com.fms.model.messaging.domain.IEmailData;

/**
 * 
 * Assembles a team of components that fufill the
 * IEmailData interface.
 * @author johnsba1
 *
 */
public class EmailDataComponents implements IEmailData
{
	private ITextSupplier	toField;
	private ITextSupplier	flowSheetFile;
	private ITextSupplier	subject;
	private ITextSupplier	message;

	/**
	 * Uses the provided parameters to fulfill the interface.
	 * 
	 * @param _toField
	 * @param _flowSheetFile
	 * @param _subject
	 * @param _message
	 */
	public EmailDataComponents(	ITextSupplier _toField, 
								ITextSupplier _flowSheetFile,
								ITextSupplier _subject,
								ITextSupplier _message)
	{
		toField = _toField;
		flowSheetFile = _flowSheetFile;
		subject = _subject;
		message = _message;
	}

	@Override
	public void addDestination(String dest)
	{
		if(toField.getText() != null && toField.getText().length() > 0)
		{
			toField.setText(toField.getText() + ";");
		}
		toField.setText(toField.getText() + dest);
	}

	@Override
	public List<String> getDestinations()
	{
		List<String> list = new ArrayList<String>();
		
		String[] tos = toField.getText().split(";");
		
		for( int i = 0; i < tos.length; i++)
		{
			list.add(tos[i]);
		}
		
		return list;
	}

	@Override
	public FlowSheet getFlowSheet()
	{
		return new FlowSheet(this.flowSheetFile.getText());
	}

	@Override
	public String getMessage()
	{
		return this.message.getText();
	}

	@Override
	public String getSubject()
	{
		return subject.getText();
	}

	@Override
	public void setFlowSheet(FlowSheet sheet)
	{
		this.flowSheetFile.setText(sheet.getFileName());
		
	}

	@Override
	public void setMessage(String message)
	{
		this.message.setText(message);
		
	}

	@Override
	public void setSubject(String subject)
	{
		this.subject.setText(subject);		
	}
}
